#!/usr/bin/env python
# -*- coding: utf-8 -*-

from web.manager.oracle_manager import OracleManager

"""
StockTransactionData的dao类
"""

class StockTransactionDataDao:
    def __init__(self):
        self.db = OracleManager()
        
    def batch_insert(self, stock_transaction_data_list):
        """
        批量插入记录
        """

        sql = ('insert into stock_transaction_data(DATE_, CODE_, OPEN_PRICE, CLOSE_PRICE, HIGHEST_PRICE, LOWEST_PRICE, '
               'LAST_CLOSE_PRICE, CHANGE_AMOUNT, CHANGE_RANGE, CHANGE_RANGE_EX_RIGHT, UP_DOWN, TURNOVER_RATE, VOLUME, TURNOVER, '
               'TOTAL_MARKET_VALUE, CIRCULATION_MARKET_VALUE, MA5, MA10, MA20, MA60, MA120, MA250, '
               'HA_OPEN_PRICE, HA_CLOSE_PRICE, HA_HIGHEST_PRICE, HA_LOWEST_PRICE, BIAS5, BIAS10, BIAS20, BIAS60, BIAS120, '
               'BIAS250, EMA12, EMA26, DIF, DEA, MACD, RSV, K, D) '
               'values(:DATE_, :CODE_, :OPEN_PRICE, :CLOSE_PRICE, :HIGHEST_PRICE, :LOWEST_PRICE, '
               ':LAST_CLOSE_PRICE, :CHANGE_AMOUNT, :CHANGE_RANGE, :CHANGE_RANGE_EX_RIGHT, :UP_DOWN, :TURNOVER_RATE, :VOLUME, :TURNOVER, '
               ':TOTAL_MARKET_VALUE, :CIRCULATION_MARKET_VALUE, :MA5, :MA10, :MA20, :MA60, :MA120, :MA250, '
               ':HA_OPEN_PRICE, :HA_CLOSE_PRICE, :HA_HIGHEST_PRICE, :HA_LOWEST_PRICE, :BIAS5, :BIAS10, :BIAS20, :BIAS60, :BIAS120, '
               ':BIAS250, :EMA12, :EMA26, :DIF, :DEA, :MACD, :RSV, :K, :D)')
        param_list = list()
        for stock_transaction_data in stock_transaction_data_list:
            param = (stock_transaction_data.date_, stock_transaction_data.code_, stock_transaction_data.open_price, stock_transaction_data.close_price,
                     stock_transaction_data.highest_price, stock_transaction_data.lowest_price, stock_transaction_data.last_close_price, stock_transaction_data.change_amount,
                    stock_transaction_data.change_range, stock_transaction_data.change_range_ex_right, stock_transaction_data.up_down, stock_transaction_data.turnover_rate,
                     stock_transaction_data.volume, stock_transaction_data.turnover, stock_transaction_data.total_market_value, stock_transaction_data.circulation_market_value,
                     stock_transaction_data.ma5, stock_transaction_data.ma10,
                    stock_transaction_data.ma20, stock_transaction_data.ma60, stock_transaction_data.ma120, stock_transaction_data.ma250, stock_transaction_data.ha_open_price,
                    stock_transaction_data.ha_close_price, stock_transaction_data.ha_highest_price, stock_transaction_data.ha_lowest_price, stock_transaction_data.bias5,
                    stock_transaction_data.bias10, stock_transaction_data.bias20, stock_transaction_data.bias60, stock_transaction_data.bias120, stock_transaction_data.bias250,
                     stock_transaction_data.ema12, stock_transaction_data.ema26, stock_transaction_data.dif, stock_transaction_data.dea, stock_transaction_data.macd,
                     stock_transaction_data.rsv, stock_transaction_data.k, stock_transaction_data.d)
            param_list.append(param)
        self.db.connect()
        self.db.batch_insert(sql, param_list)
        self.db.close()